<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		
		@media screen and (max-width:450px){
			#content{width:98%;margin:0 auto;padding:5px;border:0px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content{width:450px;margin:0 auto;padding:5px;border:0px solid}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body id='content'>
	<div style='height:100%;padding:0px' id='main' class='l1'>
		<div style='text-align:right;font-size:12px'>


			<div style='float:right' id='exitArea'>
				退出小区
			</div>
			<div style='float:right;margin-right:15px'>
				<a href="admin_list.html" style='text-decoration:none'>管理员列表</a>
			</div>
			<div style='float:right;margin-right:15px'>
				(接收推送)接收/拒收
			</div>
			<div style='float:right;margin-right:15px'>
				<span id='issue_info'>发布信息</span>
			</div>
			<div style='clear:both'></div>
		</div>

		<!--标题-->
		<h2 style='text-align:center;color:#357' id='area_name'>金达菜小区</h2>



		<!--超管投票连接-->
		<div style='margin:10px 0;word-break:break-all;display:none' id='super_admin_vote'>
			<div><a href="super_admin_vote.html" style='text-decoration:none;color:red'>关于超级管理员的任免投票通知</a></div>
		</div>


		<!--列表-->
		<div id='messageList'>
			<div style='margin:10px 0;word-break:break-all'>
				<div><a href="msg_detail.html" style='text-decoration:none'>asdfsdddddddddddddddddddddddd</a></div>
				<div style='text-align:right;font-size:12px'>发布人：征服　　2019.06.20</div>
			</div>
		</div>
		
		<div id='fpage' style='margin:30px 0;text-align:center'></div>
		
		<div style='text-align:center;margin:30px 0'>
			<button onclick='go_back()'>返回</button>
		</div>

	</div>



</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
if(!sessionStorage.current_area_id || !sessionStorage.current_area_name){
	history.go(-1);
}
C('当前小区id：'+ sessionStorage.current_area_id);

var tokenSet = GetCityInfo();
var user_info = GetUserInfo();
var area_id = sessionStorage.current_area_id;
if(!sessionStorage.area_detail_pnow){
	sessionStorage.area_detail_pnow = 1;
}

//检测超管申请
function _checkSuperAdminVote(){
	var data = {
		type:'checkSuperAdminVote',
		area_id:sessionStorage.current_area_id
	}
	AjaxBefore(data,function(res){
		C(res);
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		switch(tmp.stat){
			case 'err1':A('请求异常！');break;
			case 'have':
				$('#super_admin_vote').show();
			break;
		}
	});
}

//获取小区的信息列表
function GetAreaInfoList(){
	var data = {
		type:'GetAreaInfoList',
		area_id:sessionStorage.current_area_id,
		pnow:sessionStorage.area_detail_pnow
	}
	AjaxBefore(data,function(res){
		if(!/^{.*}$/.test(res)){
			return;
		}
		var tmp = JSON.parse(res);
		sessionStorage.token1 = tmp.token1;
		ParseData(tmp.data);
	});
}
function ParseData(data){
	var tmp_str = '';
	if(typeof(data) == 'object' && data.length > 0){
		for(var i=0;i<data.length;i++){
			var htime = StampToYmd(new Date(parseInt(data[i].time) * 1000));
			tmp_str += "<div style='margin:10px 0;word-break:break-all'><div><span onclick=JumpDetail("+data[i].id+")>"+data[i].info_title+"</span></div><div style='text-align:right;font-size:12px'>发布人："+data[i].openid+"　　"+htime+"</div></div>";
		}
		var max_page = parseInt(sessionStorage.area_detail_pnow)+1;
	}else{
		var max_page = parseInt(sessionStorage.area_detail_pnow);

	}
	if(parseInt(sessionStorage.area_detail_pnow) == 1 && tmp_str == ''){
		$('#messageList').html('');
	}else{
		$('#messageList').html(tmp_str);
		Fpage(parseInt(sessionStorage.area_detail_pnow),max_page,function(p){
			sessionStorage.area_detail_pnow = p;
				GetAreaInfoList();
		},1,1,'#fpage');
	}
}

//跳转到信息详情页
function JumpDetail(id){
	if(!id){
		return;
	}
	sessionStorage.current_msg_id = id;
	location.href='msg_detail.html';
}


$(function(){
	//检测超管申请
	_checkSuperAdminVote();

	//退出小区
	$('#exitArea').click(function(){
		localStorage.user_info = '';
		location.reload();
		return;
		location.replace('get_user_info.html');
		var data = {
			type:'exitArea',
			area_id:sessionStorage.current_area_id,
		}
		AjaxBefore(data,function(res){
			C(res);
			if(!/^{.*}$/.test(res)){
				return;
			}
			var tmp = JSON.parse(res);
			sessionStorage.token1 = tmp.token1;
			if(tmp.stat == 'ok'){
				A('操作成功！');
				location.replace('get_user_info.html');
			}else{
				A('操作异常！');
			}
		});
	});


	//获取小区的信息列表
	GetAreaInfoList(area_id);


	//发布信息
	$('#issue_info').click(function(){
		//获取指定小区的管理员列表
		GetAdminUserList(sessionStorage.current_area_id,function(data){
			//C('area_id：' + sessionStorage.current_area_id);
			var stat = false;
			for(var i=0;i<data.length;i++){
				if(user_info.openid == data[i].openid){
					stat = true;
				}
				if(stat){
					location.href='issue.html';
				}
			}
			C(stat);
		});
	});


	//显示小区名
	$('#area_name').text(sessionStorage.current_area_name+'信息列表');

});


//返回按钮
function go_back(){
	if(sessionStorage.detail_type){
		sessionStorage.detail_type = '';
		var url = 'me.html';
	}else{
		var url = 'area_list.html';
	}
	location.href=url;		
}
</script>